package org.example.volunteersystem.Mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.example.volunteersystem.entity.User;

@Mapper
public interface UserMapper {
    @Select("SELECT * FROM user WHERE username = #{username}")
    User findByUsername(String username);

    // 先判断用户名是否存在
    @Select("SELECT COUNT(*) FROM user WHERE username = #{username}")
    int countByUsername(String username);

    @Insert("INSERT INTO user(username, password, role, name, department, phone) " +
            "VALUES(#{username}, #{password}, #{role}, #{name}, #{department}, #{phone})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(User user);//这个的返回的意思是添加了多少段数据，有1段返回值就是1，0段返回值就是0
}